import { login, sysProfile, sysUser } from '@/api/user'
import { getToken, setToken, removeToken } from '@/utils/auth'
const state = {
  token: getToken() || '',
  userInfo: ''
}
const mutations = {
  setToken(state, value) {
    state.token = value
    setToken(value)
  },
  setUserInfo(state, value) {
    state.userInfo = value
  },
  loginout(state) {
    state.token = ''
    state.userInfo = ''
    removeToken()
  }
}
const actions = {
  async tologin({ commit }, value) {
    const res = await login(value)
    commit('setToken', res.data)
    // console.log('123123123');
  },
  async getUserInfo(store) {
    const res = await sysProfile()
    const res2 = await sysUser(res.data.userId)
    // console.log(res);
    // console.log(res2);
    store.commit('setUserInfo', Object.assign({}, res.data, res2.data))
  }
}
const getters = {}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
}
